package GPA;

public class Score {
    private Student student;  // 关联的学生
    private Course course;    // 关联的课程
    private double score;     // 分数

    public Score(Student student, Course course, double score) throws ScoreRangeException {
        this.student = student;
        this.course = course;
        setScore(score); // 调用setter方法触发异常检查
    }

    // 设置分数时检查范围，触发异常
    public void setScore(double score) throws ScoreRangeException {
        if (score < 0 || score > 100) {
            throw new ScoreRangeException("分数范围必须在0-100之间，当前输入：" + score);
        }
        this.score = score;
    }

    // Getter 方法
    public Student getStudent() {
        return student;
    }

    public Course getCourse() {
        return course;
    }

    public double getScore() {
        return score;
    }
}
